package GUI_Data.Staff;

import Data_Flow.GetData;
import GUI_Data.Staff.AllButtonStaff;
import GUI_Data.Staff.AllLabelAndTextFieldStaff;
import GUI_Data.User.AllBorder;
import GUI_Data.User.AllData;
import GUI_Data.User.AllLabelAndTextField;
import GUI_Data.User.SetDimension;
import lombok.Data;

import javax.swing.*;
import java.awt.*;

/**
 * This class contains all the labels and the process to add components to container.
 * @author Chunxi Lin
 */
@Data
public class AllPanelStaff {

    private JPanel headerPanel = new JPanel(new FlowLayout());
    private JPanel originPanel = new JPanel(new BorderLayout());
    private JPanel inputPanel;
    private JPanel idPanel = new JPanel(new FlowLayout());
    private JPanel centerPanel;
    private JPanel passengerPanel;
    private JPanel flightPanel = new JPanel(new GridLayout(3,1));
    private JPanel information = new JPanel(new FlowLayout());
    private JPanel finishPanel = new JPanel(new FlowLayout());

    private JPanel clickPanel = new JPanel (new GridLayout(1,1));
    //    private JPanel buttonPanel = new JPanel(new FlowLayout());
    private JPanel helpPanel = new JPanel(new FlowLayout());
    private JPanel loginPanel = new JPanel(new GridLayout(2,1));

    private JPanel rowOne = new JPanel(new GridLayout(1,10));
    private JPanel rowTwo = new JPanel(new GridLayout(1,10));
    private JPanel rowThree = new JPanel(new GridLayout(1,9));
    private JPanel rowFour = new JPanel(new GridLayout(1,9));
    private JPanel keyboardPanel = new JPanel(new GridLayout(4,1));

    /**
     * The generator of AllPanel.
     * Initialize all panels and complete the process of adding components to the container.
     * @param nowFrame User interface currently displayed (will be replaced after reset).
     * @param dimension All the dimension information.
     * @param allButton All the Button objects.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param card The CardLayout object of the center panel.
     * @param login The CardLayout object of the input panel in login page.
     * @param passenger The CardLayout object of the passengerlist panel in login page.
     */
    public AllPanelStaff(JPanel nowFrame, SetDimension dimension, AllButtonStaff allButton, AllLabelAndTextFieldStaff allLabelAndTextField, CardLayout card, CardLayout login, CardLayout passenger) {

        /* Set the page header. */
        headerPanel.setPreferredSize(dimension.getHeaderDimension());
        headerPanel.setBorder(AllBorder.panelBorder);
        headerPanel.setOpaque(false);
        headerPanel.add(allButton.getExitButton());
        headerPanel.add(allButton.getBackToOrigin());
        headerPanel.add(allButton.getBackToDisplay());

        /* Set center page. */
        centerPanel = new JPanel(card);
        centerPanel.setBorder(AllBorder.panelBorder);
        centerPanel.setPreferredSize(dimension.getCenterDimension());
        centerPanel.setOpaque(false);

        /* Set the origin page. */
//        originPanel.setBorder(panelBorder);
//        JLabel originLabel = new JLabel("Origin Page!");
//        originPanel.add(originLabel, BorderLayout.NORTH);
        originPanel.setOpaque(false);
        centerPanel.add("Origin page",originPanel);

        /* set login page */
        inputPanel = new JPanel(login);
        inputPanel.setPreferredSize(dimension.getInputDimension());
        inputPanel.setOpaque(false);
        idPanel.add(allLabelAndTextField.getInput_flightNum());
        idPanel.add(allLabelAndTextField.getNum());
        idPanel.add(keyboardPanel);
        inputPanel.add("ID", idPanel);
//        buttonPanel.add(allButton.getOriginBooking());
//        buttonPanel.add(allButton.getOriginID());
////        buttonPanel.add(allButton.getOriginScan());
//        buttonPanel.setOpaque(false);
        helpPanel.add(allButton.getOriginConfirm());
        helpPanel.setOpaque(false);
//        clickPanel.add(buttonPanel);
        clickPanel.add(helpPanel);
        clickPanel.setOpaque(false);
//        loginPanel.add(allLabelAndTextField.getInput(), BorderLayout.NORTH);
        loginPanel.add(inputPanel, BorderLayout.CENTER);
        //        loginPanel.add(keyboardPanel);
        loginPanel.add(clickPanel, BorderLayout.SOUTH);
        loginPanel.setOpaque(false);
        originPanel.add(loginPanel, BorderLayout.CENTER);

        /* set flights displaying page */
        passengerPanel = new JPanel(passenger);
        flightPanel.add(allLabelAndTextField.getFlightLabel());
        flightPanel.add(passengerPanel);
        finishPanel.add(allButton.getFinish());
        flightPanel.add(finishPanel);
        centerPanel.add("Flight page", flightPanel);


        /* Set the page header. */
        headerPanel.setPreferredSize(dimension.getHeaderDimension());
        headerPanel.setBorder(AllBorder.panelBorder);
        headerPanel.setOpaque(false);
        headerPanel.add(allButton.getExitButton());
        headerPanel.add(allButton.getBackToOrigin());
        headerPanel.add(allButton.getBackToDisplay());

        /* set keyboard panel */
        keyboardPanel.add(rowOne);
        keyboardPanel.add(rowTwo);
        keyboardPanel.add(rowThree);
        keyboardPanel.add(rowFour);
        keyboardPanel.setPreferredSize(dimension.getKeyDimension());
        for(int i = 26; i < 36; i ++){
            rowOne.add(allButton.getKeyboard3()[i]);
        }
        for(int i = 0; i < 10; i ++){
            rowTwo.add(allButton.getKeyboard3()[i]);
        }
        for(int i = 10; i < 19; i ++){
            rowThree.add(allButton.getKeyboard3()[i]);
        }
        rowFour.add(allButton.getCapsLock3());
        for(int i = 19; i < 26; i ++){
            rowFour.add(allButton.getKeyboard3()[i]);
        }
        rowFour.add(allButton.getOriginDelete3());
        keyboardPanel.setPreferredSize(new Dimension(1000,200));

        nowFrame.add(headerPanel);
        nowFrame.add(centerPanel);
    }

    /**
     * This method is called when you input targeted flight number.
     * Used to generate and add passenger listings.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     */
    public void preInit(AllLabelAndTextFieldStaff allLabelAndTextField){
        information.add(new JScrollPane(allLabelAndTextField.getPassengerTable()));
        passengerPanel.add("information", information);
    }
}
